package nuc.edu.controller;

import nuc.edu.dao.DepartmentDao;
import nuc.edu.dao.EmployeeDao;
import nuc.edu.entities.Department;
import nuc.edu.entities.Employee;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;

/**
 * Created by 张朝亮
 */
@Controller
public class DepartmentController {

    @Autowired
    EmployeeDao employeeDao;
    @Autowired
    DepartmentDao departmentDao;

    @GetMapping("/dep")
    public String ToDeptlist(Model model){
        List<Department> departments = (List<Department>) departmentDao.getDepartments();
        model.addAttribute("deptlist",departments);
        return "dep/dlist";
    }

    @GetMapping("/showdlist/{did}")
    public String ShowDeptEmployess(@PathVariable("did") Integer did, Model model){
        List<Employee> employees = employeeDao.getEmployeeByDid(did);
        model.addAttribute("employees",employees);

        return "dep/sdlist";
    }
}
